package cn.wdm.ymcc.mq;

import cn.wdm.ymcc.domain.MessageEmail;
import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SendEmailFileProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public boolean sendMessage(MessageEmail messageEmail){
        //一下操作是：为了方便消费方重新将message封装成MediaFile对象
        String jsonString = JSON.toJSONString(messageEmail);
        //  @TODO 发送异步的消息
        SendResult sendResult = rocketMQTemplate.syncSend("message-topic:message-tags", jsonString);
        SendStatus sendStatus = sendResult.getSendStatus();
        return sendStatus==SendStatus.SEND_OK;
    }
}
